import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from "vuex-persistedstate"

Vue.use(Vuex)

const store = new Vuex.Store({
    // 定义状态
    state: {
        bookDetail: {},
        userInfo: {}
    },
    //修改状态
    mutations: {
        //购买数量
        bookNum(state, msg) {
            state.bookDetail.num = msg;
        },
        //图书详情
        bookDetail(state, msg) {
            state.bookDetail = msg;
        },
        //用户信息
        userInfo(state, msg) {
            state.userInfo = msg;
        }
    },
    plugins: [createPersistedState({
        storage: window.sessionStorage,
    })],
})

export default store